<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function findLongestWord(str) {
        let arr = str.split(" ");
        let max = 1;
        for (let i = 0; i < arr.length; i++) {
          if (max < arr[i].length) {
            max = arr[i].length;
          }
        }
        console.log(max);
      }
      findLongestWord("I can write this problem");

      // function findLongestWord(str) {
      //   let arr = str.split(" ");
      //   console.log(arr);
      //   let arrL = [];
      //   for (i = 0; i < arr.length; i++) {
      //     arrL.push(arr[i].length);
      //   }
      //   a = arrL.length - 1; // 最后一项的索引
      //   console.log(arrL.sort()[a]);
      // }
      // findLongestWord("I can write this problem");

      // let a = "I can write this problem";
      // let b = a.split(" ");
      // console.log(b);
      // console.log(b.join(" "));
    </script>
  </body>
</html>
